package com.xmy.aboutdb;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * 本demo用于测试是否连接上数据库
 */
public class Demo1 {

    public static void main(String[] args) {

        String driverName = "com.mysql.cj.jdbc.Driver";

        String dbURL = "jdbc:mysql://localhost:3306/jdbcdemo?&useSSL=false"; //jdbcdemo为数据库名

        String userName = "root";

        String userPwd = "1226xmy0426";

        try {
            Class.forName(driverName);

            Connection con = DriverManager.getConnection(dbURL, userName, userPwd);

            System.out.println("连接数据库成功");

        } catch (Exception e) {

            e.printStackTrace();

            System.out.print("连接失败");

        }
    }

}